<?php
class Admin_IndexController extends Zendvn_Controller_Action{
	
	//Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	//Thong so phan trang
	protected $_paginator = array(
									'itemCountPerPage' => 5,
									'pageRange' => 3,
								  ); 
	protected $_namespace;
	
	protected  $_user;
	
	public function init(){
		//Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
		
		$template_path = TEMPLATE_PATH . "/admin/login";
		$this->loadTemplate($template_path,'template.ini','template');
		
		$this->_user = new Zend_Session_Namespace ( "user" );
	
		
		}

	public function indexAction(){
		$this->view->headTitle("Đăng nhập",true);
		if($this->_request->isPost()){
			$user =$this->_request->getParam("username");
			$pass =$this->_request->getParam("password");
			$data = new Admin_Model_Users();
			$data = $data->getWhere($user, $pass);
			if($data ==false){
				$this->view->erro ="loi";
			}
			else{
				$user = new Zend_Session_Namespace("user");
				$user->username = $data['username'];
				$user->id = $data['id'];
				$user->role =$data['role'];
				$this->_redirect("admin/control");
				
			}
		}
		
		
	}
	public function logoutAction(){
		unset($this->_user->username);
		$this->_redirect("admin/index");
	}


}